home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15753 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Stylistic Concerns with Header Files
  5. Date: Sun, 21 Apr 1996 14:36:41 GMT
  6. Organization: Netcom
  7. Message-ID: <317a471b.42264192@nntp.ix.netcom.com>
  8. References: <4lb9bl$amo@wormer.fn.net>
  9. NNTP-Posting-Host: ix-dc19-08.ix.netcom.com
  10. X-NETCOM-Date: Sun Apr 21  9:36:00 AM CDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. withheld@keepitpublic.com (Rusty Meathook) wrote:
  14.  
  15. > I occasionally create the undesirable situation of having to include
  16. > my header files in a certain order, or having to include one header
  17. > file to include another, and I was wondering how I can circumvent
  18. > that.  The most common case is something like this:
  19. > /* Untested code; call this "foo.h" */
  20. > #ifndef _FOO_H_
  21. > #define _FOO_H_
  22. > typedef struct price_tag
  23. > {
  24. >     float            cost;
  25. >     BARCODE          code;
  26. >     struct price_tag *next;
  27. > } PRICE_INFO;
  28. > #endif
  29. > /* */
  30. > /* Untested code; call this "bar.h" */
  31. > #ifndef _BAR_H_
  32. > #define _BAR_H_
  33. > typedef struct barcode_tag
  34. > {
  35. >     char             number;
  36. > } BARCODE;
  37. > #endif
  38. > /* */
  39. > Of course, these are intentionally simple examples, and there are
  40. > obvious ways to solve the problem by merging the two header files.
  41. > Imagine, however, that it is undesirable to merge the header files --
  42. > each of them deals with a different library of functions, and need to
  43. > be kept seperate to maintain modularity.
  44. > The obvious problem, now, is that a source file that needs to use
  45. > "foo.h" will have to include "bar.h" prior to including "foo.h", which
  46. > is a nasty situation stylistically.  Including another header file
  47. > within a header file is even worse.
  48. > My question is: how can you keep the two header files seperate, and
  49. > still get away with not having header file dependancies or inclusion
  50. > orders?
  51.  
  52. Why is including another header file in a header file worse?  It's
  53. often the appropriate solution.  That's what I'd do here.
  54.  
  55. Note that names beginning with an underscore and an upper case letter
  56. are reserved for use by the implementation.  You should not define
  57. such names yourself.  Use something like FOO_H instead.
  58.  
  59. Michael M Rubenstein
  60.